<div class="loginBody">
	<div class="bg"></div>
	<form class="layui-form">
		<div class="title">XXX后台管理系统</div>
		<div class="layui-form-item input-item">
			<label for="userName">用户名</label>
			<input type="text" placeholder="请输入用户名" autocomplete="off" id="userName" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item" id="imgCode">
			<label for="code">验证码</label>
			<input type="text" placeholder="请输入验证码" autocomplete="off" id="code" class="layui-input">
			<img src="http://layuicms.com/v2/images/code.jpg">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn login-btn" lay-filter="login" lay-submit="">登录</button>
		</div>
	</form>
</div>
<script type="text/javascript">
layui.use(['form','msg','jquery', 'admin', 'ajax', 'conf'],function(){
    var form = layui.form,
        $ = layui.jquery;
    var admin = layui.admin,
    	ajax = layui.ajax,
    	conf = layui.conf,
    	msg = layui.msg;

    //登录按钮
    form.on("submit(login)",function(data){
        $(this).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
        ajax.post("/admin/login", "", {
        	showTip:false,
        	ok : function(resp){
        		ajax.setToken(resp.data);
        		msg.success("登录成功", function(){
        			admin.render("/Main/", conf.layoutTarget);	
        		})
        	}
        })
        return false;
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
</script>
</html>